import http from '@/util/http'

const module = {
  namespaced: true, // 命名空间
  state: {
    categoryList: [],
    categoryNextIndex: 0
  },
  actions: {
    getCategoryMore (store, params) {
      console.log(params.path, params.start, 'category++++++++++++++++++++++++')
      http.request({
        url: `/api${params.path}/items?start=${params.start}&sort=0`
      }).then(res => {
        store.commit('pushCategoryList', res.data.data.items.list)
        store.commit('setNextIndex', res.data.data.items.nextIndex)
      })
    },
    getCategoryList (store, params) {
      console.log('33333333333', params.path)
      http.request({
        url: `/api${params.path}/items?start=${params.start}&sort=0`
      }).then(res => {
        store.commit('setCategoryList', res.data.data.items.list)
        store.commit('setNextIndex', res.data.data.items.nextIndex)
      })
    }
  },
  mutations: {
    setCategoryList (state, data) {
      console.log('setcategoryList', data)
      state.categoryList = data
    },
    pushCategoryList (state, data) {
      console.log('pushCategoryList', data)
      state.categoryList.push(...data)
    },
    setNextIndex (state, data) {
      console.log('categoryNextIndex', data)
      state.categoryNextIndex = data
    }
  }
}

export default module
